import { Game, Scene } from 'phaser'
import { MenuScene } from '../scenes/MenuScene'
import { GameScene } from '../scenes/GameScene'
import { SettingsScene } from '../scenes/SettingsScene'

export class SceneManager {
  private game: Game | null = null
  private scenes: Scene[] = []

  constructor() {
    this.initializeScenes()
  }

  /**
   * 初始化所有场景
   */
  private initializeScenes(): void {
    // 创建场景实例
    this.scenes = [new MenuScene(), new GameScene(), new SettingsScene()]
  }

  /**
   * 获取所有场景类
   */
  getScenes(): Scene[] {
    return this.scenes
  }

  /**
   * 初始化场景管理器
   */
  init(game?: Game): void {
    if (game) {
      this.game = game
    }
    console.log('SceneManager initialized')
  }

  /**
   * 启动指定场景
   */
  startScene(sceneName: string): void {
    if (this.game) {
      this.game.scene.start(sceneName)
    }
  }

  /**
   * 切换场景
   */
  switchScene(sceneName: string): void {
    if (this.game) {
      this.game.scene.start(sceneName)
    }
  }

  /**
   * 暂停当前场景
   */
  pauseScene(): void {
    if (this.game) {
      this.game.scene.pause()
    }
  }

  /**
   * 恢复当前场景
   */
  resumeScene(): void {
    if (this.game) {
      this.game.scene.resume()
    }
  }

  /**
   * 获取当前场景
   */
  getCurrentScene(): string | null {
    if (this.game) {
      return this.game.scene.getActiveScene().scene.key
    }
    return null
  }
}
